package com.wedo.mall.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.util.List;

/**
 * Created by lxy on 2017/6/19.
 */

public class Goods implements Parcelable {

    public static final String EXPRESS_0 = "0";//送货上门
    public static final String EXPRESS_1 = "1";//到店自取

    /**
     * id : 11201
     * category_id : 145
     * agent_id : 0
     * goods_name : 尼康（Nikon） D5300 单反套机（AF-P DX 尼克尔 18-55mm f/3.5-5.6G VR）灰色
     * goods_image : http://img11.360buyimg.com/n1/jfs/t2833/156/3061404369/166639/154f4854/577dd2e8N06f1bcc5.jpg
     * introduction :
     * goods_price : 3339.00
     * goods_images_id : 66447,66448,66449,66450
     * browsing_number : 12
     * collect_id
     */

    public String id;
    public String category_id;
    public String agent_category_id;
    public String agent_id;
    public String goods_name;
    public String goods_image;
    public String introduction;
    public String goods_price;
    public String goods_images_id;
    public String browsing_number;
    public String sale_number;
    public String collect_id;

    /**
     * is_recommend : 1 是否是推荐商品
     * is_auth : 1 是否是平台认证
     * goods_number : 500
     * add_time : 1496916576
     */

    public String is_recommend;
    public String is_auth;
    public int goods_number;
    /**商品属性有改变*/
    public boolean shopping_change = false;
    public String add_time;
    /**
     * attr_list :
     * is_on_sale : 1
     */

    public String attr_list;
    public String is_on_sale;
    public String relevance_id;
    public int stock_number;

    /***/
    public List<AttrItem> attrList;
    public boolean check = false;

    /**我的购物车用*/
    public String goods_id;

    public String favorable_price;
    public String express_type;//送货方式:0：送货上门，1：到店取货
    public String longitude;
    public String latitude;

    /**1表示优惠商品*/
    public int is_favorable;

    public String price(){
        if (is_favorable == 1){
            return favorable_price;
        }
        return goods_price;
    }

    public String fixPrice(){
        if (is_favorable == 1){
            return fix(favorable_price);
        }
        return fix(goods_price);
    }

    /**------7329 【商品--商品价钱--优化】商品如果没有设置价钱时把显示RM 0.00改成显示RM –-----**/
    private String fix(String str){
        if(TextUtils.isEmpty(str) || TextUtils.equals("0.00",str) || TextUtils.equals("null",str) || TextUtils.equals("0",str)||TextUtils.equals("0.0",str) ) {
            return "-";
        }
        return str;
    }

    public boolean auth(){
        return TextUtils.equals("1",is_auth);
    }

    /**是否支持某种送货方式*/
    public boolean containsExpress(String express){
        if(TextUtils.isEmpty(express_type)) {
            return false;
        }
        return express_type.contains(express);
    }

    public String pay_method;
    public boolean payable(){
        return TextUtils.isEmpty(pay_method) || TextUtils.equals("0",pay_method);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.category_id);
        dest.writeString(this.agent_id);
        dest.writeString(this.goods_name);
        dest.writeString(this.goods_image);
        dest.writeString(this.introduction);
        dest.writeString(this.goods_price);
        dest.writeString(this.goods_images_id);
        dest.writeString(this.browsing_number);
        dest.writeString(this.sale_number);
        dest.writeString(this.is_recommend);
        dest.writeString(this.is_auth);
        dest.writeInt(this.goods_number);
        dest.writeString(this.add_time);
        dest.writeString(this.attr_list);
        dest.writeString(this.is_on_sale);
        dest.writeInt(this.stock_number);
        dest.writeString(this.goods_id);
        dest.writeString(this.collect_id);
        dest.writeString(this.express_type);
        dest.writeString(this.longitude);
        dest.writeString(this.latitude);
        dest.writeInt(this.is_favorable);
        dest.writeString(this.favorable_price);
    }

    public Goods() {
    }

    protected Goods(Parcel in) {
        this.id = in.readString();
        this.category_id = in.readString();
        this.agent_id = in.readString();
        this.goods_name = in.readString();
        this.goods_image = in.readString();
        this.introduction = in.readString();
        this.goods_price = in.readString();
        this.goods_images_id = in.readString();
        this.browsing_number = in.readString();
        this.sale_number = in.readString();
        this.is_recommend = in.readString();
        this.is_auth = in.readString();
        this.goods_number = in.readInt();
        this.add_time = in.readString();
        this.attr_list = in.readString();
        this.is_on_sale = in.readString();
        this.stock_number = in.readInt();
        this.goods_id = in.readString();
        this.collect_id = in.readString();
        this.express_type = in.readString();
        this.longitude = in.readString();
        this.latitude = in.readString();
        this.is_favorable = in.readInt();
        this.favorable_price = in.readString();
    }

    public static final Parcelable.Creator<Goods> CREATOR = new Parcelable.Creator<Goods>() {
        @Override
        public Goods createFromParcel(Parcel source) {
            return new Goods(source);
        }

        @Override
        public Goods[] newArray(int size) {
            return new Goods[size];
        }
    };
}
